<?php
	$con = new mysqli("127.0.0.1","root","1982418781");
		if($con->connect_error)
		{
			die("lost:".$con->connect_error);
		}
		mysqli_select_db($con,'weather');
		mysqli_query($con,"set names utf8");
	$year = $_GET['year'];
	$month =$_GET['month'];
	$dayfrom = $_GET['dayfrom'];
	$dayto = $_GET['dayto'];
	$arr = array();
	$i=0;
	if($dayfrom>$dayto){
		$dayfrom1=1;
		switch($month){
			case 1:case 3:case 5:case 7:
			case 8:case 10:case 12: $dayto1=31;break;
			case 2:
				if($year%400==0||($year%4==0&&$year%100!=0))
				{$dayto1=29;break;}
				else{$dayto1=28;break;}
			default:$dayto1=30;
		}
		$sql1 = "select day,maxtemp,mintemp,average from am where year=$year and 
		month=$month+1 and state=1 and day between $dayfrom and $dayto1";
		$sql2 = "select day,maxtemp,mintemp,average from am where year=$year and 
		month=$month and state=1 and day between $dayfrom1 and $dayto";
		$result1 = mysqli_query($con,$sql1);
		while($row=mysqli_fetch_assoc($result1)){
			//$row['maxtemp']=$day;
			$arr[$i]=$row;
			$i++;
		}
		$result2 = mysqli_query($con,$sql2);
		while($row=mysqli_fetch_assoc($result2)){
			//$row['maxtemp']=$day;
			$arr[$i]=$row;
			$i++;
		}
		echo json_encode($arr);
		die();
	}
	$sql = "select day,maxtemp,mintemp,average from am where year=$year and 
	month=$month and state=1 and day between $dayfrom and $dayto";
	$result = mysqli_query($con,$sql);
	
	while($row=mysqli_fetch_assoc($result)){
		//$row['maxtemp']=$day;
		$arr[$i]=$row;
		$i++;
	}
	echo json_encode($arr);
?>